import Home from "./home.js"  

import store from "../../store/store";
export default React.createClass({
	getInitialState(){
        return {
            homeinit :{
            	homebanner :[],
				homeimg :"",
				homegoods:[] 
            }
        }
 }, 
 componentWillMount:function(){ 
        		store.dispatch(function(dispatch , state){
    fetch("http://www.chawo.com/mobile/index.php?act=index")
                .then(res=>res.json())
                .then(data=>{
                    dispatch({
                        type : "ADD_ITEM",
                        content : data
                    })
                })
}) 
 },    
 updateView(){ //此处为提供的更新视图方法
        var newData = store.getState(); 
        this.setState(
              {
              	homeinit :newData.homeinit
              }
        )
   },
   removeSubscribe : null,
    componentWillUnmount(){
        //组件即将被卸载  记得注销更新视图函数
        this.removeSubscribe();
    },
 componentDidMount:function(){
 	this.removeSubscribe= store.subscribe(this.updateView);
 	var that =this
 	setInterval(function(){
 		//console.log(that.state)
 	},1000)
 },
	render : function(){
		return (
			<Home  data={this.state.homeinit}/>
		)
	}
})
